package breadbox.dataManagement;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

import breadbox.client.files.Chunk;
import breadbox.client.files.FileChunk;

//this code adapted from Forrest's FileChunk class
public class ReplicationChunk extends Chunk {

	
	public ReplicationChunk(long id, byte[] d) {
		this.data = d;
		this.id = id;
	}
	
	public ReplicationChunk(byte[] b) throws IOException, ClassNotFoundException {
		// get chunk from byte[]
		ByteArrayInputStream byte_in = new ByteArrayInputStream(b);
		ObjectInputStream object_in = new ObjectInputStream(byte_in);
		ReplicationChunk k = (ReplicationChunk)object_in.readObject();
		object_in.close();
		byte_in.close();
		
		// get fields from chunk
		if (k != null) {
			this.data = k.getData();
			this.id = k.getID();
		}
	}
}
